package com.xsir.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xsir.common.Result;
import com.xsir.model.WxModel;
import com.xsir.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Type;
import java.util.List;

/**
 * @author xsir
 * @date 2020/10/11
 */
@RestController
public class WanXiangAPIController {
    private final Logger log = LoggerFactory.getLogger(getClass());
    @GetMapping("/api/news")
    @ResponseBody
    public Result getNews() {
        String news = Util.getNews("科技", 10, 0);
        log.debug(news);
        Type listType = new TypeToken<List<WxModel>>(){}.getType();
        List<WxModel> newsList = new Gson().fromJson(news, listType);
        return Result.ok().data(newsList);
    }
}
